package mspbots.cw.client.core.data.tickets;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import mspbots.cw.client.core.app.SyncRequest;
import mspbots.cw.common.QueryParams;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;

/**
 * com.mspbots.sync.wise.TicketController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/10/18
 */
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "tickets/{tenantId}")
public class TicketsController {

    private final TicketsServiceImpl entryService;

    @GetMapping("sync")
    public Mono<JsonNode> sync(@PathVariable Long tenantId, @Valid SyncRequest syncRequest) {
        return this.entryService.sync(tenantId, syncRequest);
    }

    @GetMapping("find")
    public Mono<ResponseEntity<JsonNode>> find(@PathVariable Long tenantId, @Valid QueryParams queryParams) {
        return this.entryService.find(tenantId, queryParams);
    }

    @GetMapping("project/find")
    public Mono<ResponseEntity<JsonNode>> findProject(@PathVariable Long tenantId, @Valid QueryParams queryParams) {
        return this.entryService.findProject(tenantId, queryParams);
    }


    @GetMapping("count")
    public Mono<ResponseEntity<JsonNode>> count(@PathVariable Long tenantId, @Valid QueryParams queryParams) {
        return this.entryService.count(tenantId, queryParams);
    }

    @GetMapping("notes/{ticketId}")
    public Flux<JsonNode> getNotes(@PathVariable Long tenantId, @PathVariable Long ticketId) {
        return this.entryService.getNotes(tenantId, ticketId);
    }

    @GetMapping("audit-trail/{ticketId}")
    public Flux<JsonNode> getDescription(@PathVariable Long tenantId, @PathVariable Long ticketId) {
        return this.entryService.getAuditTrail(tenantId, ticketId);
    }
}
